package com.example.bdd.demo.steps;

import com.example.bdd.demo.pages.CommonPageService;
import io.cucumber.java.After;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.When;
import lombok.extern.slf4j.Slf4j;
import org.junit.Assert;

@Slf4j
public class CommonStep {

    private CommonPageService service;

    public CommonStep(CommonPageService service) {
        this.service = service;
    }

    @Given("^I'm on the page \"([^\"]*)\" with domain \"([^\"]*)\"$")
    public void goToPage(String page, String domain) {
        service.load(domain);
        service.jumpToPage(page);
    }

    @And("^I see the page title \"([^\"]*)\"$")
    public void checkPageTitle(String title) {
        Assert.assertTrue(service.checkPageTitle(title));
    }

    @And("^I select the radio with name \"([^\"]*)\" index \"([^\"]*)\"$")
    public void selectRadio(String name, int index) {
        service.selectRadio(name, index);
    }

    @When("^I click next button$")
    public void clickNextButton() {
        service.clickNextButton();
    }

    @After
    public void afterScenario(Scenario scenarioResult) {
        log.info(">>>>>>>>>>> close page after scenario, this scenario name is [{}]", scenarioResult.getName());
        service.closePage(true);
    }

}
